home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / Mail / mail.php next >
PHP Script  |  2004-10-01  |  4KB  |  116 lines

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Chuck Hagenbuch <chuck@horde.org>                            |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: mail.php,v 1.5 2003/07/10 07:04:54 jon Exp $
  20.  
  21. require_once 'Mail.php';
  22.  
  23. /**
  24.  * internal PHP-mail() implementation of the PEAR Mail:: interface.
  25.  * @access public
  26.  * @package Mail
  27.  * @version $Revision: 1.5 $
  28.  */
  29.  
  30. class Mail_mail extends Mail
  31. {
  32.     /**
  33.      * Any arguments to pass to the mail() function.
  34.      * @var string
  35.      */
  36.     var $_params = '';
  37.  
  38.     /**
  39.      * Constructor.
  40.      *
  41.      * Instantiates a new Mail_mail:: object based on the parameters
  42.      * passed in.
  43.      *
  44.      * @param string $params Extra arguments for the mail() function.
  45.      *
  46.      * @access public
  47.      */
  48.     function Mail_mail($params = '')
  49.     {
  50.         /*
  51.          * The other mail implementations accept parameters as arrays.  In the
  52.          * interest of being consistent, explode an array into a string of
  53.          * parameter arguments.
  54.          */
  55.         if (is_array($params)) {
  56.             $this->_params = join(' ', $params);
  57.         } else {
  58.             $this->_params = $params;
  59.         }
  60.  
  61.         /*
  62.          * Because the mail() function may pass headers as command line
  63.          * arguments, we can't guarantee the use of the standard "\r\n"
  64.          * separator.  Instead, we use the system's native line separator.
  65.          */
  66.         $this->sep = (strstr(PHP_OS, 'WIN')) ? "\r\n" : "\n";
  67.     }
  68.  
  69.     /**
  70.      * Implements Mail_mail::send() function using php's built-in mail()
  71.      * command.
  72.      * 
  73.      * @param mixed $recipients Either a comma-seperated list of recipients
  74.      *              (RFC822 compliant), or an array of recipients,
  75.      *              each RFC822 valid. This may contain recipients not
  76.      *              specified in the headers, for Bcc:, resending
  77.      *              messages, etc.
  78.      *
  79.      * @param array $headers The array of headers to send with the mail, in an
  80.      *              associative array, where the array key is the
  81.      *              header name (ie, 'Subject'), and the array value
  82.      *              is the header value (ie, 'test'). The header
  83.      *              produced from those values would be 'Subject:
  84.      *              test'.
  85.      *
  86.      * @param string $body The full text of the message body, including any
  87.      *               Mime parts, etc.
  88.      *
  89.      * @return mixed Returns true on success, or a PEAR_Error
  90.      *               containing a descriptive error message on
  91.      *               failure.
  92.      * @access public
  93.      */    
  94.     function send($recipients, $headers, $body)
  95.     {
  96.         // if we're passed an array of recipients, implode it.
  97.         if (is_array($recipients)) {
  98.             $recipients = implode(', ', $recipients);
  99.         }
  100.  
  101.         // get the Subject out of the headers array so that we can
  102.         // pass it as a seperate argument to mail().
  103.         $subject = '';
  104.         if (isset($headers['Subject'])) {
  105.             $subject = $headers['Subject'];
  106.             unset($headers['Subject']);
  107.         }
  108.  
  109.         // flatten the headers out.
  110.         list(,$text_headers) = Mail::prepareHeaders($headers);
  111.  
  112.         return mail($recipients, $subject, $body, $text_headers, $this->_params);
  113.     }
  114.  
  115. }
  116.